<?php

namespace App\Admin\Controllers;

use App\Admin\Actions\Grid\AuthenticationAction;
use App\Admin\Repositories\WxAuthentication;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class WxAuthenticationController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new WxAuthentication(['user']), function (Grid $grid) {
            $grid->model()->orderBy('id','desc');
            $grid->column('user.weixin_name','用户');
            $grid->column('name');
            $grid->column('introduce')->limit(12);
            $grid->column('contact_information');
            $grid->column('identity_picture')->image('',60);
            $grid->column('overrule_content')->limit(12);
//            $grid->column('overrule_is_read');
            $grid->column('authentication_state')->using([
                0=>'审核中',
                1=>'审核通过',
                2=>'驳回'
            ])->label([
                0=>'red',
                1=>'green',
                2=>'default'
            ]);
            $grid->column('created_at');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });

            // 也可以通过这种方式添加
            $grid->actions(function (Grid\Displayers\Actions $actions) {
                $actions->append(new AuthenticationAction());
            });

            $grid->actions(function (Grid\Displayers\Actions $actions) {
                $actions->disableDelete();
                $actions->disableEdit();
                $actions->disableQuickEdit();
                $actions->disableView();
            });
            $grid->disableCreateButton();

        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new WxAuthentication(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('name');
            $show->field('introduce');
            $show->field('contact_information');
            $show->field('identity_picture');
            $show->field('overrule_content');
            $show->field('overrule_is_read');
            $show->field('authentication_state');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new WxAuthentication(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('name');
            $form->text('introduce');
            $form->text('contact_information');
            $form->text('identity_picture');
            $form->text('overrule_content');
            $form->text('overrule_is_read');
            $form->text('authentication_state');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
